package vn.conghuy.talkwithme.responsor.responsor;

import vn.conghuy.talkwithme.data.sqlmodel.SqlData;
import vn.conghuy.talkwithme.responsor.subresponsor.MyDirectionSubResponsor;
import vn.conghuy.talkwithme.responsor.subresponsor.MyLocationSubResponsor;
import vn.conghuy.talkwithme.responsor.subresponsor.NavigateMapSubResponsor;
import vn.conghuy.talkwithme.responsor.subresponsor.ShowLocationOnMapSubResponsor;
import vn.conghuy.talkwithme.utils.Utils;
import android.content.Context;

public class MapResponsor extends Responsor {
	
	public static final int RELATIVE_SHOW_LOCATION = 1;
	public static final int RELATIVE_NAVIGATE = 2;
	
	MyLocationSubResponsor myLocationSubResponsor;
	MyDirectionSubResponsor myDirectionSubResponsor;
	ShowLocationOnMapSubResponsor showLocationSubResponsor;
	NavigateMapSubResponsor navigateSubResponsor;
	
	public MapResponsor(Context context) {
		super(context);
		myLocationSubResponsor = new MyLocationSubResponsor(this, context);
		myDirectionSubResponsor = new MyDirectionSubResponsor(this, context);
		showLocationSubResponsor = new ShowLocationOnMapSubResponsor(this, context);
		navigateSubResponsor = new NavigateMapSubResponsor(this, context);
	}
	
	@Override
	public String response(String request) {
		
		if(Utils.isExistStringInArray(SqlData.stopWords, request) == true){
			relativeLastResponse = RELATIVE_NONE;
			return Utils.getRandomString(SqlData.taskStop);
		}
		
		String result;
		
		if(relativeLastResponse != RELATIVE_NONE){
			switch (relativeLastResponse) {
			case RELATIVE_SHOW_LOCATION:
				return showLocationSubResponsor.response(request);
			case RELATIVE_NAVIGATE:
				return navigateSubResponsor.response(request);
			}
		}
		
		result = myDirectionSubResponsor.response(request);
		if(result != null) return result;
		result = showLocationSubResponsor.response(request);
		if(result != null) return result;
		result = navigateSubResponsor.response(request);
		if(result != null) return result;
		result = myLocationSubResponsor.response(request);
		if(result != null) return result;

		return super.response(request);
	}
	
	@Override
	public void reset() {
		super.reset();
		navigateSubResponsor.reset();
		showLocationSubResponsor.reset();
	}
}
